﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class manage_notice_list : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {            
                GridView1_DataBind();
        }
    }

    private void GridView1_DataBind()
    {
        String sql = "select id, title, contents, addtime, link, case del_flg when 0 then '不显示' when 1 then '显示' end as del_flg from t_notice";
        GridView1.DataSource = DataBaseOperate_SQLServer.GetDataTable(sql);
        GridView1.DataBind();
    }

    protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        //进行分页之后，重新部署数据
        GridView1_DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //分页完成之前
        GridView1.PageIndex = e.NewPageIndex;
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "View")
        {
            int ID = Convert.ToInt32(e.CommandArgument);
            Response.Redirect("notice_view.aspx?id="+ID.ToString());
        }
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //获取要删除的记录的id并赋值给变量ID        
        int ID = Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[0].Text);
        String sql = "delete from t_notice where id=" + ID.ToString();
        DataBaseOperate_SQLServer.ExecUpdate(sql);
        GridView1_DataBind();
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Response.Redirect("notice_add.aspx");
    }
}
